package com.zhoushihao.class0814;

import java.util.*;

class AttendanceRecord {
    private String empId;
    private String name;
    private String date;
    private String checkInTime;
    private String checkOutTime;

    public AttendanceRecord(String empId, String name, String date, String checkInTime, String checkOutTime) {
        this.empId = empId;
        this.name = name;
        this.date = date;
        this.checkInTime = checkInTime;
        this.checkOutTime = checkOutTime;
    }

    public String getEmpId() {
        return empId;
    }

    public String getName() {
        return name;
    }

    public String getDate() {
        return date;
    }

    public String getCheckInTime() {
        return checkInTime;
    }

    public String getCheckOutTime() {
        return checkOutTime;
    }
}

public class AttendanceAnalysis {

    //9:00--18:00
    public static void main(String[] args) throws Exception {
        String[] data = {
                "E1001,张三,2025-08-01,09:05,18:30",
                "E1002,李四,2025-08-01,08:30,19:00",
                "E1003,王五,2025-08-01,09:15,18:10",
                "E1001,张三,2025-08-02,09:00,18:10",
                "E1002,李四,2025-08-02,09:02,18:05",
                "E1003,王五,2025-08-02,09:05,17:55",
                "E1001,张三,2025-08-03,09:10,18:50"
        };

        List<AttendanceRecord> records = new ArrayList<>();

        for (String line : data) {
            String[] parts = line.split(",");
            records.add(new AttendanceRecord(parts[0], parts[1], parts[2], parts[3], parts[4]));
        }
        Map<String, Integer> lateMap = new HashMap<>();
        Map<String, Double> addMap = new HashMap<>();
        int startTime = 9 * 60;
        int backTime = 18 * 60;
        int normalWorkTime = backTime - startTime;
        for (AttendanceRecord record : records) {
            String[] str1 = record.getCheckInTime().split(":");
            String[] str2 = record.getCheckOutTime().split(":");
            int checkInTime = Integer.parseInt(str1[0]) * 60 + Integer.parseInt(str1[1]);
            int checkOutTime = Integer.parseInt(str2[0]) * 60 + Integer.parseInt(str2[1]);
            int workingTime = checkOutTime - checkInTime;
            if (checkInTime > startTime) {
                lateMap.put(record.getName(), lateMap.getOrDefault(record.getName(), 0) + 1);
                if (workingTime > normalWorkTime) {
                    addMap.put(record.getName(), addMap.getOrDefault(record.getName(), 0.0) + (workingTime - normalWorkTime) * 1.0 / 60);
                } else {
                    addMap.put(record.getName(), addMap.getOrDefault(record.getName(), 0.0));
                }
            } else {
                if (checkOutTime > backTime) {
                    addMap.put(record.getName(), addMap.getOrDefault(record.getName(), 0.0) + (checkOutTime - backTime) * 1.0 / 60);
                }
                lateMap.put(record.getName(), lateMap.getOrDefault(record.getName(), 0));
                addMap.put(record.getName(), addMap.getOrDefault(record.getName(), 0.0));
            }
        }
        System.out.println("1. 每名员工迟到次数");
        for (Map.Entry<String, Integer> entry : lateMap.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        System.out.println("2. 每名员工总加班时长");
        for (Map.Entry<String, Double> entry : addMap.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
}


